import React from 'react';
import { inject, observer } from 'mobx-react';
import { Spin } from 'antd'

const toJS = mobx.toJS;
import LoadLogs from '../../../public/loadlog/loadLogs';
import { WeaNewScroll,WeaLocaleProvider } from 'ecCom';
import { getParams, getCurrentHeight, setWindowKeys } from '../../../util/Util';
const getLabel = WeaLocaleProvider.getLabel;
@inject('planViewStore')
@observer
export default class PlanLog extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            _height:getCurrentHeight()
        };
        this.store = this.props.planViewStore;
    }


    componentWillMount(){
      //  this.store.getPlanLog()
    }

    getNameALink = (resourceid, resourcename) => {
        let href = 'javaScript:openhrm(' + resourceid + ');';
        return (
            <a href={href} onClick={e => window.pointerXY(e)} class="autoWrap">
                {resourcename}
            </a>
        );
    };

    morePlanLog = () => {
        this.store.morePlanLog()
        this.store.getPlanLog();
    };
    scrollToAnchor = anchorName => {
        if (anchorName) {
            let anchorElement = document.getElementById(anchorName);
            if (anchorElement) {
                anchorElement.scrollIntoView();
            }
        }
    };
    render() {
        let { planLog } = this.store;
        let {_height} = this.state
        planLog = toJS(planLog);
        const { datas } = planLog;
        if (datas) {
            for (var i = 0; i < datas.length; i++) {
                datas[i].operatevalue = datas[i].operatetype;
            }
        }

        return (
            <div className="planlog" id="plan-log">
                <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@i6gw99`} height={_height - 180}>
                    <LoadLogs ecId={`${this && this.props && this.props.ecId || ''}_LoadLogs@okq09f`}
                        morename={this.store.planLog.logType == 'noView' ? getLabel('20234', '显示全部') : getLabel('387979', '加载更多')}
                        moretitle={
                            this.store.planLog.logType == 'noView' ? getLabel('509061', '显示包括查看在内的所有日志记录') : getLabel('387979', '加载更多')
                        }
                        onMoreClick={this.morePlanLog}
                        lastcount={planLog.lastcount}
                        logsData={datas}
                    />
                    </WeaNewScroll>
            </div>
        );
    }
}
